<?php 
	$strStyleSheet = TRUE;
	
	/* Read in the array of classes */
	if(file_exists(MODULE_SHOP_HOST . "/utility/class_registry_".SHOP_HOST.".php"))
	{
		if(!include(MODULE_SHOP_HOST . "/utility/class_registry_".SHOP_HOST.".php"))
		{
			print("Unable to include 'class registry'<br>\n");
			exit();
		}else{
			$strRegistryName = "arrRegister".SHOP_HOST."Class";
			$arrRegisterClass = $$strRegistryName;
			//print_r($arrRegisterClass);
		}
	}
	/* 
	** set constants
	*/
	if(!include(MODULE . "/utility/configuration.php"))
	{
		print("Unable to include 'configuration'<br>\n");
		exit();
	}
	/*
	** set local constants
	*/
	if(!include(MODULE . "/custom_config/".SHOP_HOST."Configuration.inc"))
	{
		print("Unable to include 'configuration'<br>\n");
		exit();
	}
	$strConfig = MODULE . "/custom_config/".SHOP_HOST."Configuration";
	/*
	** get library of standard functions
	*/
	if(!include(MODULE . "/utility/standard_library.php"))
	{
		print("Unable to include 'standard_library'<br>\n");
		exit();
	}
	
	/* get library of form validation functions	*/
	if(!include(MODULE . "/utility/validate_input.php"))
	{
		print("Unable to include 'validate_input'<br>\n");
		exit();
	}

	
	if(!include(MODULE . "/utility/initialization.php"))
	{
		print("Unable to include 'initialization'<br>\n");
		exit();
	}

	/*
	** perform init code needed with every page view
	*/
	if(!include(MODULE_SHOP_HOST . "/utility/".SHOP_HOST."DBinitialization"))
	{
		print("Unable to include 'DBinitialization'<br>\n");
		exit();
	}
	/*
	** Execute action module, if requested.
	** Check for actions that include paths or other suspicious characters.
	*/
	if(isset($ACTION) AND ($ACTION != ""))
	{
		if(eregi('^[A-Z_0-9]*$', $ACTION) AND
			file_exists(MODULE . "/action/$ACTION"))
		{
			//try, as much as possible, to disallow actions from being interrupted
			set_time_limit(ACTION_TIME_LIMIT);
			$userAbortOrig = ignore_user_abort(TRUE);
			
			if(!include(MODULE . "/action/$ACTION"))
			{
				array_push($ActionResults, "'$ACTION' failed!");
			}
			
			//restore default settings
			set_time_limit(DEFAULT_TIME_LIMIT);
			ignore_user_abort($userAbortOrig);
		}
		else 
		{
			array_push($ActionResults, "'$ACTION' is not a valid action.");
		}
	}	
	
	/*
	** include array of screen information
	*/
	require(MODULE_SHOP_HOST . "/utility/".SHOP_HOST."ScreenInfo");
	require(MODULE . "/utility/ScreenInfo.php");
	$ScreenInfo = array_merge_recursive ($ScreenInfoPart2, $ScreenInfoPart1);

	//check to see if current screen should be encrypted
		if($ScreenInfo[$SCREEN][SI_SECURE] == TRUE){
			//echo "secure ".$ScreenInfo[$SCREEN][SI_SECURE];
			global $SECURESCREEN;
			$SECURESCREEN = TRUE;
			
			//session_register(sesSecureScreen);
		}else{
			//echo "not secure ".$ScreenInfo[$SCREEN][SI_SECURE];
			//$_SESSION['sesSecureScreen'] = FALSE;
		}

	/*
	** If we aren't given a screen, go home
	*/
	//echo "SCREEN = $SCREEN";
	if(!(isset($SCREEN)) OR ($SCREEN==""))
	{
		$SCREEN="welcome";
	}
	
	
	/*
	** If screen is private and valid user is not logged in, $SCREEN is reset
	*/
	if($ScreenInfo[$SCREEN][SI_TYPE] == "private") {
		if (($_SESSION['sesUserName']) AND ($_SESSION['sesUserType'] == "staff")){
			
		}else{
			$SCREEN="scrLogin";
		}
	}
	
	//reset customer screen if valid user is not logged in
	if($ScreenInfo[$SCREEN][SI_TYPE] == "customerprivate") {
		if (($_SESSION['sesUserName']) and (($_SESSION['sesUserType'] == "customer") OR ($_SESSION['sesUserType'] == "staff"))){
		
		}else{
			$SCREEN="scrLogin";
		}
	}

	/*
	** If screen is bad, go home
	*/
	if(!(file_exists(MODULE_SHOP_HOST . "/screen/$SCREEN"))OR (!isset($ScreenInfo[$SCREEN]))){
			if(!(file_exists(MODULE . "/screen/$SCREEN"))OR (!isset($ScreenInfo[$SCREEN]))){
				$SCREEN_LOCATION = MODULE;
				$SCREEN="welcome";
			}else{
				$SCREEN_LOCATION = MODULE;
				
			}
	}else{
		$SCREEN_LOCATION = MODULE_SHOP_HOST;
	}
	
	
	/*
	** Start page
	*/
	
	if(!include(MODULE . "/action/actDynamicMetaTags.php")){
		print("An error occurred while creating dynamic meta tags<br>\n");
	}
	
	if($ScreenInfo[$SCREEN]['SI_LAYOUT'] != "eBay_Template"){
	?>
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		
			<head>
			<title><?php echo $ScreenInfo[$SCREEN][SI_TITLE] ?></title>
			<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
			<?php
				//if($_SESSION['sesUserType'] == "staff")
				//{
					echo "<link rel=\"stylesheet\" href=\"/vendere-css/vendere.css\" type=\"text/css\" />";
				//}
			?>
			<link rel="stylesheet" href="/shop<?php echo SITE_SUFFIX ?>.css" type="text/css" />	
			<link rel="stylesheet" media="print" href="/print<?php echo SITE_SUFFIX ?>.css" type="text/css" />
			<link rel="stylesheet" href="/vendere-jscript/lightbox/css/lightbox.css" type="text/css" media="screen" />
			
			<meta name="description" content="<?php echo $ScreenInfo[$SCREEN][SI_DESCRIPTION]?>" />
			<meta name="keywords" content="<?php echo $ScreenInfo[$SCREEN][SI_KEYWORDS]?>" />
			<meta name="distribution" content="global" />
			</head>
		
		
			<body>
		<?php
			if ($Browser_JavaScriptOK == TRUE){
		
			
				/*
				** include javascript for image rollover
				*/
		
				if 	(($ScreenInfo[$SCREEN][SI_LAYOUT] == "pop_up_window")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "pop_up_window_no_header")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "system_admin")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "without_side_nav_calendar")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "with_side_nav_nojs"))
				{
					//include nothing
				}else{
					
					if(!include(MODULE . "/action/rollover")){
						print("An error occurred while laying out the page<br>\n");
					}
					
					if(file_exists(MODULE_SHOP_HOST . "/utility/".MENUDEF)){
						include(MODULE_SHOP_HOST . "/utility/".MENUDEF);
					}else{
						if(!include(MODULE . "/utility/".MENUDEF)){
							print("Unable to include 'Java menu'<br>\n");
							exit();
						}
					}
				}
			}
		
			if ($Browser_JavaScriptOK == TRUE){
					if 	(($ScreenInfo[$SCREEN][SI_LAYOUT] == "pop_up_window")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "pop_up_window_no_header")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "system_admin")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "without_side_nav_calendar")
						||
						($ScreenInfo[$SCREEN][SI_LAYOUT] == "with_side_nav_nojs")){
				    }else{
				    	?>
						<script language='javascript1.2' src='menu.js' type='text/javascript'></script>
						<script type="text/javascript" src="/vendere-jscript/lightbox/js/prototype.js"></script>
						<script type="text/javascript" src="/vendere-jscript/lightbox/js/scriptaculous.js?load=effects"></script>
						<script type="text/javascript" src="/vendere-jscript/lightbox/js/lightbox.js"></script>
						
					<?php
					}
			}
		/*
			if($_SERVER['REMOTE_ADDR'] == '82.69.116.105')
			{
				error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
				//echo "<br/>\$SCREEN".$SCREEN;
				//echo "<br/>".MODULE_SHOP_HOST . "/layout/".$ScreenInfo[$SCREEN][SI_LAYOUT]."<br>";
				//print_array($ScreenInfo['test']);
			}
		/*/
			/*
			** go to layout module, that will in turn use navigation and screen modules
			Check to see if customer layouts exist, if they do use them else use supplied templates.
			*/
			//echo MODULE_SHOP_HOST . "/layout/".$ScreenInfo[$SCREEN][SI_LAYOUT]."<br>";
			if(!(file_exists(MODULE_SHOP_HOST . "/layout/".$ScreenInfo[$SCREEN][SI_LAYOUT])))
			{
				
				// include default layout as customer layout doesn't exist
				if(!include(MODULE . "/layout/".$ScreenInfo[$SCREEN][SI_LAYOUT])){
						print("<br>An error occurred while laying out the page<br>\n");
				}
				
		
			}else{
				//If it does exist
				if(!include(MODULE_SHOP_HOST . "/layout/".$ScreenInfo[$SCREEN][SI_LAYOUT])){
					print("An error occurred while laying out the page<br>\n".MODULE_SHOP_HOST . "/layout/".$ScreenInfo[$SCREEN][SI_LAYOUT]);
				}
			
			}  
			
			//Log web usage if Google Analytics has been set-up and it's not staff using the site
			if(file_exists(MODULE_SHOP_HOST . "/screen/GoogleAnalytics.php") && (!isset($_SESSION['sesUserType']) || ($_SESSION['sesUserType'] != "staff")))
			{
				//include Google conversion script
				include(MODULE_SHOP_HOST . "/screen/GoogleAnalytics.php");
			}	 

		
		?>
		</body>
		</html>
	<?
	}else{
		if(!include(MODULE . "/layout/".$ScreenInfo[$SCREEN][SI_LAYOUT])){
		print("An error occurred while laying out the page<br>\n");
		}
	
	}
	?>
